﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Student.ViewModel.Enum
{
    /// <summary>
    /// 定义执行结果：枚举类型
    /// </summary>
    public enum ResultCode
    {
        /// <summary>
        /// 执行成功
        /// </summary>
        Success = 0,

        /// <summary>
        /// 执行失败
        /// </summary>
        Busy = -1,

        /// <summary>
        /// 缺少Token
        /// </summary>
        TokenMissing = 10000,

        /// <summary>
        /// Token验证失效
        /// </summary>
        TokenError = 10001,
    }

    /// <summary>
    /// 扩展的自调用方法：方便根据代码获取对应的信息
    /// </summary>
    public static class ResultCodeExtension
    {
        public static string GetMsg(this ResultCode resCode)
        {
            var msg = string.Empty;
            switch (resCode)
            {
                case ResultCode.Success:
                    msg = "成功";
                    break;
                case ResultCode.Busy:
                    msg = "系统忙";
                    break;
                case ResultCode.TokenMissing:
                    msg = "缺少登录信息，请重新登录";
                    break;
                case ResultCode.TokenError:
                    msg = "登录信息过期，请重新登录";
                    break;
            }
            return msg;
        }
    }
}
